<template>
	<view class="submit">
		<!-- #ifdef APP-PLUS -->
		<Hearder :name="'确认订单'"></Hearder>
		<!-- #endif -->
		<view style="padding-bottom: 150rpx;">
			<view class="submit_t">
				<view class="list" @click="toPage('/pages/personal/AddressList?type=1')" >
				  <view class="list-content" v-if="data.exist_address">
				    <view style="font-weight:700;word-break: break-all;">
				  		{{data.address.detail}}
					</view>
					<view class="confirm-details">
					  <text style="margin-right:50rpx">{{data.address.name}}</text>
					  <text>{{data.address.phone}}</text>
					</view>
				  </view>
				  <view v-else class="list-content noaddress">
					<image src="../../static/images/address1.png"></image>
				  	<text>添加地址</text>
				  </view>
				 <view class="aside">
					 <u-icon name="arrow-right" color="#ccc" size="18"></u-icon>
				  </view>
				</view>
				<view style="margin-top: -30rpx;">
					<image src="../../static/images/line.png" style="position: relative;top: 12rpx;width:100%;height:6rpx;"></image>
				</view>
			</view>
			<view class="shopping-list">
				<view class="shopping_main clearfix" v-for="item in data.goods_list">
					<view class="shopping-list-left">
						<image :src="item.image[0].file_path"></image>
					</view>
					<view class="shopping-list-right">
						<view class="shopping_tit">
							<view class="title">{{item.goods_name}}</view>
							<view class="shop_sku" v-if="item.goods_sku.goods_attr"><text> {{item.goods_sku.goods_attr}}</text></view>
						</view>
						<view class="shopping_bot">
							<view v-if="type!=4">￥{{item.goods_price}}</view>
							<view v-if="type==4">{{item.score_price}}积分</view>
							<view>x{{item.total_num}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="moneys-con">
				<view class="moneys-every">
					<view>商品金额</view>
					<view v-if="type!=4">￥{{data.order_total_price}}</view>
					<view v-if="type==4">{{data.order_total_score_price}}积分</view>
				</view>
				<view class="heji">
					需支付：
					<text v-if="type!=4">￥{{data.order_pay_price}}</text>
					<text v-if="type==4">{{data.order_pay_score_price}}积分</text>
				</view>
			</view>
			<view class="moneys-con" v-if="type!=4" @click="toPage('lootorder')">
				<view class="moneys-every" style="padding: 30rpx 0;">
					<view>选择抵扣订单</view>
					<view v-if="goods_order_id.length">
						<text style="font-size: 26rpx;">
							共
							<text style="color:#D61B30">{{goods_order_id.length}}</text>
							单
						</text>
						<u-icon name="arrow-right" color="#323232" size="16"></u-icon>
					</view>
					<view v-else>
						<text style="font-size: 26rpx;">选择订单</text>
						<u-icon name="arrow-right" color="#323232" size="16"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view class="pay-bumit" @tap="$u.throttle(paymoney, 1000)">提交订单</view>
		<shopro-login-modal :showLogin="showLogin" @loginhidden="loginhidden"></shopro-login-modal>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				marqueeList:'',
				type:1, // 1商城  2购物车  4积分
				data:{},
				showLogin:false,
				goods_num:1,
				goods_sku_id:'',
				mobanopen:{},
				goods_order_id:''
			}
		},
		onLoad(options) {
			this.type = options.type || this.$route.query.type
			this.goods_id = options.id || this.$route.query.id
			if(options.goods_sku_id){
				this.goods_sku_id = options.goods_sku_id
			}
			if(options.goods_num){
				this.goods_num = options.goods_num
			}
		},
		onShow() {
			if(uni.getStorageSync('goods_order_id')){
				this.goods_order_id = uni.getStorageSync('goods_order_id')
				uni.removeStorageSync('goods_order_id')
			}
			if(this.type!=2){
				this.request('/order/buyNow',{
					goods_sku_id:this.goods_sku_id,
					goods_id:this.goods_id,
					goods_num:this.goods_num,
					order_type:this.type
				},'GET').then(res => {
					if(res.data.code==-500){
						this.showLogin=true
					}
					if(res.data.code==1){
						this.data =res.data.data 
					}
				})
			}else if(this.type==2){
				this.request('/order/toCartOrder',{
					goods_sku_id:this.goods_sku_id,
					goods_id:this.goods_id
				},'GET').then(res => {
					if(res.data.code==-500){
						this.showLogin=true
					}
					if(res.data.code==1){
						this.data =res.data.data 
					}
				})
			}
		},
		methods:{
			paymoney(){
				var that = this
				if(this.type!=2){
					var url = '/order/buyNow'
					var data = {
						goods_sku_id:this.goods_sku_id,
						goods_num:this.goods_num,
						goods_id:this.goods_id,
						order_type:this.type,
						goods_order_id:this.goods_order_id
					}
				}else if(this.type==2){
					var url = '/order/toCartOrder'
					var data = {
						goods_sku_id:this.goods_sku_id,
						goods_id:this.goods_id,
						goods_order_id:this.goods_order_id
					}
				}
				this.request(url,data).then(res => {
					if(res.data.code==1){
						let order_sn = res.data.data.order_sn
						if(this.type!=4){
							uni.redirectTo({
								url: '/pages/classify/order?type=forwarding'
							});
						}else{
							this.request('/pay/pointsPayment',{trade_no:order_sn}).then(res => {
								if(res.data.code==1){
									setTimeout(()=>{
										uni.redirectTo({
											url: '/pages/common/result?success=1&id='+this.goods_id
										});
									},500)
								}else{
									this.$tip(res.data.msg)
								}
							})
						}
					}else{
						this.$tip(res.data.msg)
					}
				})
			},
			loginhidden(data){
				this.showLogin=data
			},
			toPage(route){
				uni.navigateTo({
				    url: route
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.submit{
		overflow: hidden;
		min-height: 100%;
		background: $uni-background-color;
		.submit_t,
		.shopping-list,
		.moneys-con,
		.macon-con{
			margin-top: 20rpx;
			background: #fff;
		}
		.submit_t{
			.list{
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 3%;
			}
			.list-content{
				width: 94%;
				display: flex;
				flex-direction:column;
				justify-content: space-between;
				.confirm-details{
					margin-top: 20rpx;
				}
			}
			.noaddress{
			    display: block !important;
			    height:150rpx;
			    text-align: center;
			    image{
				    width: 36rpx;
				    height: 36rpx;
					margin: -4rpx 10rpx 0 0;
			    }
			    text{
				    line-height: 150rpx;
				    text-align: center;
				    color: #999;
			    }
			}
		}
		.shopping-list{
			padding: 3%;
			.shopping_main{
				margin-top: 22rpx;
				&:first-of-type{
					margin-top: 0;
				}
				.shopping-list-left{
					float: left;
					image{
						width: 188rpx;
						height: 188rpx;
					}
				}
				.shopping-list-right{
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					float: left;
					margin-left: 25rpx;
					width: calc(100% - 213rpx);
					height: 188rpx;
					.shopping_tit{
						.title{
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							font-size: 28rpx;
						}
						.biaoqian{
							font-size: 24rpx;
							color: #999;
							margin-top: 10rpx;
						}
					}
					.shopping_bot{
						display: flex;
						justify-content: space-between;
						view{
							font-size: 28rpx;
							&:last-of-type{
								font-size: 30rpx;
								color: #999;
							}
						}
					}
				}
			}
		}
		.moneys-con{
			padding: 0 3%;
			.moneys-every{
				display: flex;
				justify-content: space-between;
				padding: 20rpx 0;
				view{
					font-size: 28rpx;
				}
			}
			.heji{
				padding: 20rpx 0;
				text-align: right;
				font-weight: 800;
				text{
					color: $uni-text-color;
					font-weight: 800;
				}
			}
		}
		.pay-bumit{
			position: fixed;
			bottom: 0;
			width: 100%;
			height: 98rpx;
			background: $uni-item-color;
			color: #fff;
			text-align: center;
			line-height: 98rpx;
		}
	}
</style>